<template>
  <div class="page-header-index-wide page-header-wrapper-grid-content-main">
    <a-row :gutter="24">

      <a-spin :style=" spinning ? `top: 300px;left: 50%;position: fixed;z-index: 10000;` : `display:none;` " />

      <a-col :md="24" :lg="5">

        <div class="recommended-books">
          <div class="title">
            <span>📚 图书榜</span>
          </div>
          <ul>
            <li class="book-item">
              <a href="/books/18" target="_blank">
                <img class="book-item-img" src="https://img.golang123.com/upload/img/2018/06/5f111fe1-f6f3-4cb0-a0eb-6cb0458e206a.jpg">
                <div class="book-item-info">
                  <div class="book-item-title">Node.js 调试指南</div>
                  <div>
                    <span class="book-item-buycount">9人已学习</span>
                    <span class="try-read">阅读</span>
                  </div>
                </div>
              </a>
            </li>
            <li class="book-item">
              <a href="/books/43" target="_blank">
                <img class="book-item-img" src="https://img.golang123.com/upload/img/2018/04/cb4e1ba4-9fb5-44f4-9873-50672dc7478e.jpg">
                <div class="book-item-info">
                  <div class="book-item-title">ECMAScript 6 入门</div>
                  <div>
                    <span class="book-item-buycount">5人已学习</span>
                    <span class="try-read">阅读</span>
                  </div>
                </div>
              </a>
            </li>
          </ul>
        </div>

        <div class="recommended-authors">
          <div class="title">
            <span style="color: #333;">🎖️ 作者榜</span>
          </div>
          <ul class="list">
              
            <li class="item" :key="index" v-for=" (item , index) in newAuthors ">
              <div class="link">
                <a @click="$router.push(`/account/author/${item.username}`)" target="_blank" class="recommended-avatar" :style="`background-image: url(${item.avatar});`"></a>
                <div class="user-info">
                  <a @click="$router.push(`/account/author/${item.username}`)" target="_blank" class="username">{{item.realname}}</a>
                  <a target="_blank" class="rank">
                    <img :src="`https://cdn.jsdelivr.net/gh/Miazzy/yunwisdoms@v3.0.0/images/${item.level}.svg`">
                  </a>
                  <div class="position"></div>
                  <div class="description">{{ item.bio }}</div>
                </div>
              </div>
            </li>
            
            <li class="item">
              <a @click="$router.push(`/account/authors/index`);" target="_blank" class="more">
                <span>完整榜单</span>
                <i class="fa fa-angle-right" style="font-size: 16px;"></i>
              </a>
            </li>
          </ul>
        </div>

        <div class="sidebar-block related-entry-sidebar-block shadow" st:block="relatedEntrySidebarBlock">
          <div class="block-title">🔥  最新文章</div>

          <div class="block-body">
            <div class="entry-list" :key="index" v-for="(item , index) in newBlogData ">
              <a @click="handleBlogView(item)" target="_blank" rel="" st:name="link" class="item" >
                <div class="entry-title" style="cursor: pointer;"><a>{{item.title}}</a></div>
                <div class="entry-meta-box">
                  <div class="entry-meta"><img src="//cdn.jsdelivr.net/gh/Miazzy/yunwisdoms@v3.0.0/images/zan.svg" class="icon"><span class="count">{{item.star}}</span></div>
                  <div class="entry-meta"><img src="//cdn.jsdelivr.net/gh/Miazzy/yunwisdoms@v3.0.0/images/comment.svg" class="icon"><span class="count">{{item.messages}}</span></div>
                </div>
              </a>
            </div>
          </div>
        </div>

      </a-col>

      <a-col :md="24" :lg="19">
        
        <div class="main-box">
          <div class="major-box">
            <div class="user-info-block">
              <div class="user-info-block-avatar" :style="`background-image: url(${nowAuthor.avatar});`"></div>
              <div class="info-box">
                <div class="top">
                  <h1 class="username"> {{ `${nowAuthor.realname} ` }} 
                    <a href="/" target="_blank" class="rank">
                      <img :src="`https://cdn.jsdelivr.net/gh/Miazzy/yunwisdoms@v3.0.0/images/${nowAuthor.level}.svg`">
                    </a>
                  </h1>
                </div>
                <div class="position"><svg width="21" height="18" viewBox="0 0 21 18" class="position-icon"><g fill="none" fill-rule="evenodd"><path fill="#72777B" d="M3 8.909V6.947a1 1 0 0 1 1-1h13a1 1 0 0 1 1 1V8.92l-6 2.184v-.42c0-.436-.336-.79-.75-.79h-1.5c-.414 0-.75.354-.75.79v.409L3 8.909zm0 .7l6 2.184v.47c0 .436.336.79.75.79h1.5c.414 0 .75-.354.75-.79v-.46l6-2.183V16a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V9.609zm6.75 1.075h1.5v1.58h-1.5v-1.58z"></path> <path stroke="#72777B" d="M7.5 5.213V4A1.5 1.5 0 0 1 9 2.5h3A1.5 1.5 0 0 1 13.5 4v1.213"></path></g></svg>                            
                  <span class="content"> {{ `${nowAuthor.realname} | ${nowAuthor.username} | ${postName} | ${departName}` }} </span>
                </div>
                <div class="intro"><svg width="21" height="18" viewBox="0 0 21 18" class="intro-icon"><path fill="#72777B" fill-rule="evenodd" d="M4 4h13a1 1 0 0 1 1 1v9a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1zm9 6a2 2 0 1 0 0-4 2 2 0 0 0 0 4zm3 3a3 3 0 0 0-6 0h6zM5 7v1h4V7H5zm0 2.5v1h4v-1H5zM5 12v1h4v-1H5z"></path></svg>
                  <span class="content"> {{ nowAuthor.bio }} </span>
                </div>
              </div>
              <div class="action-box" v-if=" $route.params.id != userInfo.username ">
                <button :style=" (nowWatchFlag ? `color:#fff;background-color:#6cbd45;` : ``) " @click="handleWatchAuthor(nowAuthor.username)" class="subscribe-btn follow-btn author-watch-btn" >
                  {{ nowWatchFlag ? '已关注':'关注' }}
                </button>
              </div>
            </div>

            <div class="list-block">
              <div class="detail-list">
                <div class="list-header">
                  <div class="header-content">
                    <a @click="handlePageType('article')" :class=" nowPageType == 'article' ? 'nav-item router-link-exact-active router-link-active active' : 'nav-item' " style="margin-left:10px;">
                      <div class="item-title">文章</div>
                      <div class="item-count">{{nowAuthor.blogs}}</div>
                    </a>
                    <a @click="handlePageType('attention')" :class=" nowPageType == 'attention' ? 'nav-item router-link-exact-active router-link-active active' : 'nav-item' ">
                      <div class="item-title">关注</div>
                    </a>
                    <a @click="handlePageType('handbooks')" :class=" nowPageType == 'handbooks' ? 'nav-item router-link-exact-active router-link-active active' : 'nav-item'">
                      <div class="item-title">小册</div>
                    </a>
                    <a @click="handlePageType('collections')" :class=" nowPageType == 'collections' ? 'nav-item router-link-exact-active router-link-active active' : 'nav-item'">
                      <div class="item-title">收藏集</div>
                    </a>
                  </div>
                </div>

                <div class="list-body" v-show="nowPageType == 'article' ">
                  <div class="post-list-box">

                    <div class="sub-header">
                      <div class="sub-header-title">文章</div>
                      <div class="sub-type-box">
                        <a @click="handleBlogType('hot')" id="sub-article-type-hot" :class=" nowBlogType == 'hot' ? 'sub-type active' : 'sub-type' ">热门</a> 
                        <a @click="handleBlogType('new')" id="sub-article-type-new" :class=" nowBlogType == 'new' ? 'sub-type active' : 'sub-type' ">最新</a>
                      </div>
                    </div>

                    <div class="article-list" :key="index" v-for="(item , index) in nowBlogData">
                      <div class="article-list-item" style="min-height: 0px;">

                        <div class="article-content">
                          <div class="article-content-and-img">
                            <div class="article-title-summary"><a @click="$router.push(`/blog/view?id=${item.id}&author=${item.create_by}&tags=${tags}`)" target="_blank" class="article-title">{{item.title}}</a>
                              <p class="article-content">{{ `${item.description.slice(0,150)}...` }}</p>
                            </div>
                          </div>
                          <div class="article-meta">
                            <div class="article-view-like">
                              <a target="_blank" class="article-username">{{ nowAuthor.realname }}</a>
                              <a target="_blank" @click="$router.push(`/blog/view?id=${item.id}&author=${item.create_by}&tags=${tags}`)">
                                <img src="https://cdn.jsdelivr.net/gh/Miazzy/yunwisdom_zhao_cdn@v1.0.0/images/read.svg" class="icon" style="margin-top:-3px;margin-right:2px;width:20px;opacity:0.4;filter:alpha(opacity=40);" >
                                {{ item.visit_count }} 
                              </a> 
                              <a target="_blank" @click="$router.push(`/blog/view?id=${item.id}&author=${item.create_by}&tags=${tags}`)">
                                <img src="//cdn.jsdelivr.net/gh/Miazzy/yunwisdoms@v3.0.0/images/comment.svg" class="icon" style="margin-top:-3px;margin-right:2px;" >{{ item.messages }}
                              </a>
                              <a href="javascript:void(0)" style="color: rgb(180, 180, 180); cursor: default;">
                                <img src="//cdn.jsdelivr.net/gh/Miazzy/yunwisdoms@v3.0.0/images/zan.svg" class="icon" style="margin-top:-3px;margin-right:2px;" > {{ item.star }}
                              </a> 
                              <span class="time">{{ item.create_time }}</span></div>
                          </div>
                        </div>
                      </div>
                    </div>

                  </div>
                </div>

                <div class="list-body" v-show="nowPageType == 'attention' ">
                  <div class="post-list-box" >
                    <div class="sub-header">
                      <div class="sub-header-title">关注</div>
                      <div class="sub-type-box">
                        <a @click="handleWatchType('self')" :class="watchTypeFlag == 'self' ? 'sub-type active router-link-exact-active router-link-active' : 'sub-type' " >关注了</a> 
                        <a @click="handleWatchType('fans')" :class="watchTypeFlag == 'fans' ? 'sub-type active router-link-exact-active router-link-active' : 'sub-type' " >粉丝</a> 
                        <a @click="handleWatchType('tags')" :class="watchTypeFlag == 'tags' ? 'sub-type active router-link-exact-active router-link-active' : 'sub-type' " >关注标签</a>
                      </div>
                    </div>
                    <div :key="watchTypeFlag" v-show=" watchTypeFlag == 'fans' && nowFans != null ">
                      <div :key="index" v-for="(item , index) in nowFans ">
                        <a target="_blank" class="link user-follow-item">
                          <div class="lazy avatar avatar loaded" :style="`background-image: url(&quot;${imageURL}/${item.avatar}&quot;);`"></div>
                          <div class="info-box">
                            <a target="_blank" class="username">{{ `${item.realname}` }}
                            </a>
                            <div class="detail">{{ `${item.fans}` }}</div>
                          </div> <button :style=" (myWatchString.includes(`,${item.fans},`) ? `color:#fff;background-color:#6cbd45;` : ``) " @click="myWatchString.includes(`,${item.fans},`) ? (handleClearWatch(item.fans)) : (handleWatchAuthor(item.fans)) " class="subscribe-btn follow-btn followed" v-if="userInfo.username != item.fans" >{{ (spinning === true && nowloadname === item.fans)? '关注中' : (myWatchString.includes(`,${item.fans},`) ? '已关注' : '关注') }}</button>
                        </a>
                      </div>
                    </div>
                    <div :key="watchTypeFlag" v-show=" watchTypeFlag == 'self' && nowWatchs != null ">
                      <div :key="index" v-for="(item , index) in nowWatchs ">
                        <a target="_blank" class="link user-follow-item">
                          <div class="lazy avatar avatar loaded" :style="`background-image: url(&quot;${imageURL}/${item.avatar}&quot;);`"></div>
                          <div class="info-box">
                            <a target="_blank" class="username">{{ `${item.realname}` }}
                            </a>
                            <div class="detail">{{ `${item.watch}` }}</div>
                          </div> <button :style=" (myWatchString.includes(`,${item.watch},`) ? `color:#fff;background-color:#6cbd45;` : ``) " @click="myWatchString.includes(`,${item.watch},`) ? (handleClearWatch(item.watch)) : (handleWatchAuthor(item.watch)) " class="subscribe-btn follow-btn followed" v-if="userInfo.username != item.watch" >{{ (spinning === true && nowloadname === item.watch)? '关注中' : (myWatchString.includes(`,${item.watch},`) ? '已关注' : '关注') }}</button>
                        </a>
                      </div>
                    </div>
                  </div>
                </div>

              </div>
            </div>
          </div>
          <div class="minor-box">
            <div class="minor-area-box">
              <div class="user-stat-block">
                <div class="block-title">个人成就</div>
                <div class="block-body">
                  <div class="stat-item"><svg width="25" height="26" viewBox="0 0 25 26" class="zan-icon"><g fill="none" fill-rule="evenodd" transform="translate(0 .57)"><ellipse cx="12.5" cy="12.57" fill="#fadcd6" rx="12.5" ry="12.57"></ellipse> <path fill="#e77c6a" d="M8.596 11.238V19H7.033C6.463 19 6 18.465 6 17.807v-5.282c0-.685.483-1.287 1.033-1.287h1.563zm4.275-4.156A1.284 1.284 0 0 1 14.156 6c.885.016 1.412.722 1.595 1.07.334.638.343 1.687.114 2.361-.207.61-.687 1.412-.687 1.412h3.596c.38 0 .733.178.969.488.239.317.318.728.21 1.102l-1.628 5.645a1.245 1.245 0 0 1-1.192.922h-7.068v-7.889c1.624-.336 2.623-2.866 2.806-4.029z"></path></g></svg>                                
                    <span class="content">获得点赞<span class="count">{{nowAuthor.stars}}</span></span>
                  </div>
                  <div class="stat-item"><svg width="25" height="25" viewBox="0 0 25 25" class="article-view-icon"><g fill="none" fill-rule="evenodd"><circle cx="12.5" cy="12.5" r="12.5" fill="#fadcd6"></circle> <path fill="#e77c6a" d="M4 12.5S6.917 7 12.75 7s8.75 5.5 8.75 5.5-2.917 5.5-8.75 5.5S4 12.5 4 12.5zm8.75 2.292c1.208 0 2.188-1.026 2.188-2.292 0-1.266-.98-2.292-2.188-2.292-1.208 0-2.188 1.026-2.188 2.292 0 1.266.98 2.292 2.188 2.292z"></path></g></svg>                                
                    <span class="content">文章被阅读<span class="count">{{nowAuthor.visits}}</span></span>
                  </div>
                  <div class="stat-item"><svg width="25" height="25" viewBox="0 0 25 25" class="stat-jp-icon"><g fill="none" fill-rule="evenodd"><circle cx="12.5" cy="12.5" r="12.5" fill="#fadcd6"></circle> <path fill="#e77c6a" d="M16.694 13.516l-3.719 3.055a1.1 1.1 0 0 1-1.412-.013l-2.77-2.362-3.597 2.437a.693.693 0 0 1-.895-.101.649.649 0 0 1-.008-.876l3.68-4.096a1.1 1.1 0 0 1 1.507-.122l2.653 2.135 2.248-2.4-1.34-1.358a.5.5 0 0 1 .327-.85l5.438-.313a.5.5 0 0 1 .528.533l-.368 5.449a.5.5 0 0 1-.855.317l-1.417-1.435z"></path></g></svg>                                
                    <span class="content">获得喜欢<span class="count">{{nowAuthor.favors}}</span></span>
                  </div>
                </div>
              </div>
              <div class="follow-block">
                <a @click="handlePageType('attention');handleWatchType('self');" class="follow-item">
                  <div class="item-title">关注</div>
                  <div class="item-count">{{ nowWatchs.length }}</div>
                </a>
                <a @click="handlePageType('attention');handleWatchType('fans');" class="follow-item">
                  <div class="item-title">粉丝</div>
                  <div class="item-count">{{ nowFans.length }}</div>
                </a>
              </div>
              <div class="more-block">
                <a @click="handlePageType('collections');" class="more-item">
                  <div class="item-title">收藏集</div>
                  <div class="item-count">0</div>
                </a>
                <a @click="handlePageType('attention');handleWatchType('tags');" class="more-item">
                  <div class="item-title">关注标签</div>
                  <div class="item-count">0</div>
                </a>
                <div class="more-item" >
                  <div class="item-title">加入于</div>
                  <div class="item-count"><time class="time">{{ nowJointime }}</time></div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </a-col>
    </a-row>
  </div>
</template>

<script>
import PageLayout from "@/components/page/PageLayout";
import RouteView from "@/components/layouts/RouteView";
import { ArticlePage } from "./page";
import * as manageAPI from "@/api/manage";
import * as storage from "@/utils/storage";
import * as tools from "@/utils/util";
import * as authortool from "@/api/blogAPI/author";
import * as hashtoken from "@/api/hashToken/hashtoken";

export default {
  components: {
    RouteView,
    PageLayout,
    ArticlePage,
  },
  data() {
    return {
      tags: [],
      imageURL:window._CONFIG['uploadURL'],
      postName: "",
      departName: "",
      address: "",
      bio: "",
      tagInputVisible: false,
      tagInputValue: "",
      tabListNoTitle: JSON.parse(`[{"key":"推荐文章","tab":"推荐文章","index":0},{"key":"社会聚焦","tab":"社会聚焦","index":1},{"key":"科学技术","tab":"科学技术","index":2},{"key":"人工智能","tab":"人工智能","index":3},{"key":"诸子百家","tab":"诸子百家","index":4},{"key":"金融管理","tab":"金融管理","index":5},{"key":"建筑工程","tab":"建筑工程","index":6},{"key":"艺术设计","tab":"艺术设计","index":7},{"key":"团队文化","tab":"团队文化","index":8},{"key":"问答交流","tab":"问答交流","index":9},{"key":"前端开发","tab":"前端开发","index":10},{"key":"Android","tab":"Android","index":11},{"key":"IOS开发","tab":"IOS开发","index":12},{"key":"后端开发","tab":"后端开发","index":13}]`),
      fdata: null,
      userinfo: null,
      v_user: null,
      newBlogData:null,
      nowBlogData:null,
      nowBlogType:'hot',
      nowPageType:'article',
      nowWatchFlag: false,
      watchTypeFlag: 'self',
      newAuthors:null,
      nowFans:null,
      nowWatchs:null,
      nowJointime:'',
      myWatchs:null,
      nowAuthor:null,
      routeParams:null,
      routeQuery:null,
      myWatchString:null,
      nowloadname:null,
      spinning:false,
      noTitleKey: "推荐文章"
    };
  },
  computed: {
    userInfo() {
      return this.$store.getters.userInfo;
    }
  },
  /**
   * @function 初始化
   */
  async created() {
    //页面创建初始化操作
    await this.initAuthorPage();
    //设置tab栏类型
    await this.handlePageType('article');
  },
  async mounted() {
    
  },
  watch: {
    $route(to, from) {
      //页面跳转初始化操作
      this.initAuthorPage();
    }
  },
  methods: {
    ...Vuex.mapGetters(["nickname", "avatar"]),
    async initAuthorPage(){
        //获取用户信息
        this.user = this.userInfo;

        //设置员工岗位信息/部门信息
        try {
          storage.setStore(`system_title_key`,this.noTitleKey);

          this.routeParams = this.$route.params ;
          this.roueteQuery = this.$route.query ;

          this.v_user = await manageAPI.queryUserInfoByView(this.$route.params.id);

          this.postName = this.v_user[0]["post"];
          this.departName = this.v_user[0]["name"];
          this.address = this.v_user[0]["address"];
          this.bio = this.v_user[0]["bio"];
          this.avatar = this.v_user[0]["avatar"];

          this.v_user[0]["tags"] = this.v_user[0]["tags"].replace(/，/g, ",");
          this.tags = this.v_user[0]["tags"].split(",");

          //排行榜作者
          this.newAuthors = await authortool.queryAuthorRank(0, 3, storage , tools);

          //当前作者
          this.nowAuthor = (await authortool.queryAuthorByID(this.$route.params.id , storage , tools))[0];

          //最新前十博文
          this.newBlogData = await manageAPI.queryBlogInfo(0 , 5);

          //检查关注状态
          this.nowWatchFlag = await this.handleWatchFlag();

          try {
            //获取用户粉丝/关注者
            this.nowFans = await this.handleAuthorFans(this.$route.params.id);
            this.nowWatchs = await this.handleAuthorWatchs(this.$route.params.id);
            this.nowJointime = await this.queryJoinTime(this.$route.params.id);
          } catch (error) {
            console.log(error);
          }

          try {
            //获取缓存中的关注用户信息
            //let watchs = storage.getStore(`system_user_${this.userInfo.username}_watch_users_cache`);
            //获取用户粉丝/关注者
            this.myWatchs = await this.handleMyWatchs();
            //获取关注用户字符串
            this.myWatchString = (this.myWatchs.map(obj => {return obj.watch})).toString();
            //设置关注用户字符串
            this.myWatchString = `,${this.myWatchString},`;
          } catch (error) {
            console.log(error);
          }

          try {
            //获取当前关注用户
            var watchList = this.myWatchs;
            //检查粉丝等用户是否被当前用户关注
            this.nowFans.each((item) => {
              let flag = watchList.find( (watch) => {
                return watch.watch == item.fans || watch.username == item.fans
              });
              item.flag = tools.isNull(flag) ? false : true;
            });
            this.nowWatchs.each((item) => {
              let flag = watchList.find( (watch) => {
                return watch.watch == item.watch || watch.username == item.watch
              });
              item.flag = tools.isNull(flag) ? false : true;
            });
          } catch (error) {
            console.log(error);
          }

          try {
            //当前作者博文数据
            this.nowBlogData = await this.handleBlogType(this.nowBlogType);
          } catch (error) {
            console.log(error);
          }

        } catch (error) {
          console.log("工作台设置员工岗位信息/部门信息异常：" + error);
        }
    },
    /**
     * @function 处理关注标识
     */
    async handleWatchFlag(){
      var result = await this.queryTableDataByWhere('bs_blog_attention',`_where=(create_user,eq,${this.userInfo.username})~and(watch_user,eq,${this.$route.params.id})`);
      if(result){
        this.nowWatchFlag = true;
        return true;
      } else {
        this.nowWatchFlag = false;
        return false;
      }
    },
    /**
     * @function 获取用户的粉丝
     */
    async handleAuthorFans(username , expiretime = 3600){
      this.nowFans = await this.queryWatchsAll(0 , 99 , 'fans' , 'v_fans' , username , 10 , expiretime);
      return this.nowFans;
    },
    /**
     * @function 获取用户的关注用户
     */
    async handleAuthorWatchs(username , expiretime = 3600){
      this.nowWatchs = await this.queryWatchsAll(0 , 99 , 'watch' , 'v_watch' , username , 10 , expiretime);
      return this.nowWatchs;
    },
    /**
     * @function 查询所有用户信息，目前只查询前1000个用户信息
     */
    async handleAuthorAll(){
      this.nowAuthors = await this.queryAuthorsAll(0 , 99 , 'exp' , 10);
      return this.nowAuthors;
    },
    /**
     * @function 获取当前用户的关注用户
     */
    async handleMyWatchs(page = 0 , size = 99 , times = 10 , expiretime = 10){
      if(this.$route.params.id === this.userInfo.username){
        size = Math.round(Math.random() * 50) + 50;
        size = size >= 100 ? Math.round(Math.random() * 50) + 50 : size;
        times = Math.round(1000 / size) + 1 ;
        this.myWatchs = await this.queryWatchsAll(page , size , 'watch' , 'v_watch' , this.userInfo.username , times , expiretime);
        this.nowWatchs = this.myWatchs;
      } else {
        size = Math.round(Math.random() * 50) + 50;
        size = size >= 100 ? Math.round(Math.random() * 50) + 50 : size;
        times = Math.round(1000 / size) + 1 ;
        this.myWatchs = await this.queryWatchsAll(page , size , 'watch' , 'v_watch' , this.userInfo.username , times , expiretime);
      }
      return this.myWatchs;
    },
    /**
     * @function tab栏关注界面关注/粉丝/标签切换
     */
    async handleWatchType(type){
      this.watchTypeFlag = type;
      return this.watchTypeFlag;
    },
    /**
     * @function 切换博文类型
     */
    async handleBlogType(type){
      //获取博文类型对应字段
      var stype = authortool.queryBlogTypeValue(type);
      //热门 和 最新 博文之间进行切换
      this.nowBlogType = type;
      //计算相应的博文数据
      this.nowBlogData = await authortool.queryBlogsAllByAuthor(0 , 99 , this.$route.params.id , stype , 10 , storage , tools , true);
      //返回相应的博文数据
      return this.nowBlogData;
    },
    /**
     * @function 切换Tab栏类型
     */
    async handlePageType(type){
      //tab栏之间互相切换
      this.nowPageType = type;
      //返回Tab栏类型
      return this.nowPageType;
    },
    /**
     * @function 关注当前博客作者
     */
    async handleWatchAuthor(username){
      //设置加载状态
      await (() => {this.spinning = true; this.nowloadname = username })();
      //执行关注操作
      if(!this.myWatchString.includes(`,${username},`)){
        //设置loading状态
        await tools.sleep(100);
        //进行关注操作
        var result = await authortool.handleWatchAuthor(this.userInfo.username, username, this, storage , tools, hashtoken);
        //获取关注的缓存
        this.myWatchString = `${this.myWatchString},${username},`
        //将新关注的放入缓存
        storage.setStore(`system_user_${this.userInfo.username}_watch_users_cache` , this.myWatchString , 3600 * 2);
        //取消loading状态
        await (() => { this.spinning = false; })();
        //设置关注操作，返回数据
        return result;
      } else {
        //显示提示内容
        this.$message.success('你已经关注过此用户啦！');
        //取消loading状态
        await (() => { this.spinning = false; })();
        //设置关注操作，返回数据
        return false;
      }
    },
    /**
     * @function 执行取消关注函数
     */
    async handleClearWatch(username){
      //设置加载状态
      await (() => {this.spinning = true; this.nowloadname = username })();
      //执行取消关注操作
      if(this.myWatchString.includes(`,${username},`)){
        //sleep 300ms , 等待loading状态渲染完成
        await tools.sleep(100);
        //执行取关
        let result = authortool.handleClearWatch(this.userInfo.username, username, this, storage, tools, hashtoken);
        let arr = this.myWatchString.split(',');
        arr = arr.filter( (item , index , array) => {
            return item && item.trim() && item !== username && item !== 'undefined' && item !== 'null' && array.indexOf(item) === index; 
        });
        //获取关注的缓存
        this.myWatchString = `,${arr},`;
        //将新关注的放入缓存
        storage.setStore(`system_user_${this.userInfo.username}_watch_users_cache` , this.myWatchString , 3600 * 2);
        //取消loading状态
        await (() => { this.spinning = false; })();
        //设置关注操作，返回数据
        return result;
      } else {
        //取消loading状态
        await (() => { this.spinning = false; })();
        //设置关注操作，返回数据
        return false;
      }
    },
    /**
     * @function 查询用户的创建时间
     */
    async queryJoinTime(username){
      let jointime =  await authortool.queryTableDataByWhere('v_user', `_fields=create_time&_where=(username,eq,${username})`, storage, tools, 3600 * 24 * 365);
      return tools.formatDate(jointime.create_time , 'yyyy-MM-dd');
    },
    /**
     * @function 查询所有用户信息
     */
    async queryAuthorsAll(page = 0, size = 99 , type = 'exp' , times = 10 , expiretime = 3600){
      return await authortool.queryAuthorsAll(page , size , type , times , storage, tools, expiretime);
    },
    /**
     * @function 查询所有用户信息
     */
    async queryWatchsAll(page = 0, size = 99 , type = 'watch' , table = 'v_watch', username , times = 10 , expiretime = 3600){
      return await authortool.queryWatchsAll(page , size , type , table , username , times , storage , tools , expiretime);
    },
    /**
     * @function 查询数据
     * @param {*} tableName
     * @param {*} id
     */
    async queryTableDataByWhere(tableName, whereSQL){
        return await authortool.queryTableDataByWhere(tableName, whereSQL, storage, tools, 3600 * 2);
    },
    /**
     * @function 查询数据
     * @param {*} tableName
     * @param {*} id
     */
    async queryTableDataByWhereMore(tableName, whereSQL){
        return await authortool.queryTableDataByWhereMore(tableName, whereSQL , storage, tools , 3600 * 2);
    },
    /**
     * @function 处理切换书签功能
     */
    async handleTabChange(key, type) {
      return await authortool.handleAuthorTabChange(key, type, storage, manageAPI);
    },
    /**
     * @function 处理博文预览功能
     */
    async handleBlogView(item) {
      return await authortool.handleIntoBlogView(item , tools , this);
    }
  }
};
</script>

<style lang="scss" scoped>

.page-header-wrapper-grid-content-main {
  width: 100%;
  height: 100%;
  min-height: 100%;
  transition: 0.3s;

  a {
    color: #2d8cf0;
    background: 0 0;
    text-decoration: none;
    outline: 0;
    cursor: pointer;
    transition: color .2s ease;
  }

  .author-watch-btn {
    background-color: rgb(255, 255, 255); 
    border-color: rgb(108, 189, 69); 
    color: rgb(108, 189, 69);
    border: 1px solid rgb(108,189,69); 
    width: 108px; 
    height: 34px; 
    border-radius: 6px; 
    font-size: 16px; 
    font-weight: 500;
  }

  .main-box {
    width: 90%;
    display: flex;
    margin: 20px auto 32px;
    margin-top: 0;
    margin-left: 0;
    margin-bottom: 32px;
  }

  .major-box {
    flex: 1 1 auto;
    min-width: 0;
  }

  .user-info-block {
    display: flex;
    padding: 30px;
    background-color: #fff;
    border-radius: 2px;
    box-shadow: 0 1px 2px 0 rgba(0,0,0,.05);
  }

  .user-info-block-avatar {
    display: inline-block;
    position: relative;
    background-position: 50%;
    background-size: cover;
    background-repeat: no-repeat;
    flex: 0 0 auto;
    margin-right: 28px;
    width: 90px;
    height: 90px;
    background-color: #f9f9f9;
    border-radius: 50%;
  }

  .user-info-block .info-box {
    display: flex;
    flex-direction: column;
    justify-content: center;
    flex: 1 1 auto;
    margin-right: 24px;
  }

  .user-info-block .info-box .top {
    display: flex;
    align-items: center;
  }

  .user-info-block .info-box .top .username {
    margin: 0;
    padding: 0;
    font-size: 26px;
    font-weight: 600;
    line-height: 1.2;
    color: #000;
  }

  .rank {
    margin-left: 4px;
    vertical-align: middle;
  }

  .info-box .position {
    margin-top: 12px;
    display: flex;
    font-size: 15px;
    line-height: 1.5;
    color: #72777b;
  }

  .info-box .position-icon {
    flex: 0 0 auto;
    margin-right: 7px;
    height: 22px;
  }

  svg:not(:root) {
    overflow: hidden;
  }

  .info-box .position .content {
    flex: 1 1 auto;
    font-size: 14px;
  }

  .info-box .intro {
    margin-top: 5px;
    display: flex;
    font-size: 15px;
    line-height: 1.5;
    color: #72777b;
  }

  .info-box .intro-icon {
    flex: 0 0 auto;
    margin-right: 7px;
    height: 22px;
  }

  .user-info-block .action-box {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
  }

  .follow-btn {
    flex: 0 0 auto;
    margin: 0 0 0 12px;
    padding: 0;
    width: 90px;
    height: 30px;
    font-size: 12px;
    color: #92c452;
    background-color: #fff;
    border: 1px solid #92c452;
    border-radius: 2px;
    outline: none;
    transition: background-color .3s,color .3s;
    cursor: pointer;
  }

  .list-block {
    margin-top: 12px;
  }

  .list-header {
    position: relative;
    margin: 0;
    padding: 0;
    height: 50px;
    background-color: #fff;
    border-radius: 2px 2px 0 0;
    border-bottom: 1px solid #ebebeb;
    z-index: 100;
  }

  .list-header .header-content {
    display: flex;
    align-items: center;
    margin: 0 auto;
    height: 100%;
    max-width: 960px;
    white-space: nowrap;
  }

  .list-header .nav-item.active {
    box-shadow: inset 0 -2px 0 #ea6f5a;
  }

  .list-header .nav-item {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    width: 90px;
    height: 100%;
    cursor: pointer;
    text-decoration: none;
  }

  .list-header .nav-item.active .item-count, .list-header .nav-item.active .item-title {
    color: #ea6f5a;
  }

  .list-header .nav-item .item-title {
      font-size: 16px;
      font-weight: 500;
      color: #31445b;
  }

  .list-header .nav-item.active .item-count, .list-header .nav-item.active .item-title {
      color: #ea6f5a;
  }

  .list-header .nav-item .item-count {
      margin-left: 5px;
      font-size: 15px;
      color: #b2bac2;
      line-height: 1;
  }

  .list-header .nav-item {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    width: 90px;
    height: 100%;
    cursor: pointer;
    text-decoration: none;
  }

  .post-list-box, .sub-header {
    background-color: #fff;
  }

  .post-list-box, .sub-header {
    background-color: #fff;
  }

  .list-body .sub-header {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    padding: 0 20px;
    height: 50px;
    white-space: nowrap;
    border-bottom: 1px solid rgba(230,230,231,.5);
  }

  .list-body .sub-header {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    padding: 0 20px;
    height: 50px;
    white-space: nowrap;
    border-bottom: 1px solid rgba(230,230,231,.5);
  }

  .list-body .sub-header .sub-header-title {
    margin-right: 12px;
    font-size: 15px;
    font-weight: 600;
    color: #000;
  }

  .post-list-box, .sub-header {
    background-color: #fff;
  }

  .list-body .sub-header .sub-header-title {
    margin-right: 12px;
    font-size: 15px;
    font-weight: 600;
    color: #000;
  }

  .list-body .sub-header .sub-type-box {
    margin-left: auto;
  }

  .list-body .sub-header .sub-type-box .sub-type:not(:last-child) {
    margin-right: 24px;
  }

  .list-body .sub-header .sub-type-box .sub-type.active {
    color: #000;
  }

  .list-body .sub-header .sub-type-box .sub-type:not(:last-child) {
    margin-right: 24px;
  }

  .list-body .sub-header .sub-type-box .sub-type {
      position: relative;
      padding: 12px 0;
      font-size: 14px;
      color: #72777b;
  }

  .link:not(:last-child) {
    border-bottom: 1px solid rgba(230,230,231,.5);
  }

  .link{
      display: flex;
      align-items: center;
      padding: 6px 20px;
      min-height: 84px;
  }

  .avatar {
    display: inline-block;
    position: relative;
    background-position: 50%;
    background-size: cover;
    background-repeat: no-repeat;
    background-color: #eee;
    flex: 0 0 auto;
    margin-right: 20px;
    width: 45px;
    height: 45px;
    border-radius: 50%;
  }

  .info-box {
    flex: 1 1 auto;
    min-width: 0;
  }

  .info-box .username {
    font-size: 16px;
    font-weight: 600;
    color: #2e3135;
  }

  .info-box .detail {
    margin-top: 7px;
    font-size: 12px;
    font-weight: 500;
    color: #b9c0c8;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .list-body .sub-header {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    padding: 0 20px;
    height: 50px;
    white-space: nowrap;
    border-bottom: 1px solid rgba(230,230,231,.5);
  }

  .post-list-box, .sub-header {
    background-color: #fff;
  }

  .list-body .sub-header .sub-header-title {
    margin-right: 12px;
    font-size: 15px;
    font-weight: 600;
    color: #000;
  }

  .list-body .sub-header .sub-type-box {
    margin-left: auto;
  }

  .list-body .sub-header .sub-type-box .sub-type:not(:last-child) {
    margin-right: 24px;
  }

  .list-body .sub-header .sub-type-box .sub-type {
      position: relative;
      padding: 12px 0;
      font-size: 14px;
      color: #72777b;
  }

  .list-body .sub-header .sub-type-box .sub-type.active {
    color: #000;
  }

  .article-list {
    width: 100%;
  }

  .article-list-item {
      padding: 20px;
      margin-bottom: 0;
      box-sizing: border-box;
  }

  .article-list-item {
      position: relative;
      width: 100%;
      margin: 0;
      padding: 20px;
      box-sizing: border-box;
      border-bottom: 1px solid #f0f0f0;
      word-wrap: break-word;
  }

  .list-body .sub-header .sub-type-box .sub-type {
      position: relative;
      padding: 12px 0;
      font-size: 14px;
      color: #72777b;
  }

  .article-content {
      margin-bottom: 0;
  }

  .article-content {
      margin: 0 0 8px;
      font-size: 13px;
      line-height: 24px;
      color: #999;
  }

  .article-content-and-img {
    display: flex;
    margin-bottom: 8px;
  }

  .article-title-summary {
    flex: 1;
  }

  .article-title {
    margin-top: 0;
  }

  .iconfont {
    font-family: iconfont!important;
    font-size: inherit;
    font-style: normal;
    font-weight: 400!important;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }

  .ic-list-read:before {
    content: "\E662";
  }

  .article-title:visited {
      color: #909090;
  }

  .article-title {
      font-size: 18px;
      font-weight: 700;
      line-height: 1.5;
      color: #333;
      margin: -7px 0 4px;
      display: inherit;
  }

  .article-content {
    margin-bottom: 0;
  }

  .article-content {
      margin: 0 0 8px;
      font-size: 13px;
      line-height: 24px;
      color: #999;
  }

  .article-meta {
      display: flex;
  }

  .article-meta {
      padding-right: 0!important;
      font-size: 12px;
      font-weight: 400;
      line-height: 20px;
  }

  .article-view-like {
    flex: 1;
  }

  .article-meta a {
    transition: .1s ease-in;
    -webkit-transition: .1s ease-in;
    -moz-transition: .1s ease-in;
    -o-transition: .1s ease-in;
    -ms-transition: .1s ease-in;
    margin-right: 10px;
    color: #b4b4b4;
  }

  .iconfont {
    font-family: iconfont!important;
    font-size: inherit;
    font-style: normal;
    font-weight: 400!important;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }

  .article-meta a {
    transition: .1s ease-in;
    -webkit-transition: .1s ease-in;
    -moz-transition: .1s ease-in;
    -o-transition: .1s ease-in;
    -ms-transition: .1s ease-in;
    margin-right: 10px;
    color: #b4b4b4;
  }

  .article-meta span {
    margin-right: 10px;
    color: #b4b4b4;
    font-size: 12px;
    font-weight: 400;
    line-height: 20px;
  }

  .minor-box {
    flex: 0 0 auto;
    margin-left: 12px;
    width: 240px;
    line-height: 14px;
  }

  .minor-area-box {
    width: 240px;
    transition: all .2s;
  }

  .user-stat-block {
    margin-bottom: 12px;
    background-color: #fff;
    border-radius: 2px;
    box-shadow: 0 1px 2px 0 rgba(0,0,0,.05);
  }

  .user-stat-block .block-title {
    padding: 16px;
    font-size: 16px;
    font-weight: 600;
    color: #31445b;
    border-bottom: 1px solid rgba(230,230,231,.5);
  }

  .user-stat-block .block-body {
    padding: 16px;
  }

  .user-stat-block .block-body .stat-item:not(:last-child) {
    margin-bottom: 10px;
  }

  .user-stat-block .block-body .stat-item {
      display: flex;
      align-items: center;
      font-size: 15px;
      color: #000;
  }

  .user-stat-block .block-body .stat-item .article-view-icon, .user-stat-block .block-body .stat-item .zan-icon , .user-stat-block .block-body .stat-item .stat-jp-icon {
    flex: 0 0 auto;
    margin-right: 14px;
  }

  .user-stat-block .block-body .stat-item .count {
    margin: 0 5px;
    font-weight: 500;
  }

  .follow-block {
    display: flex;
    position: relative;
    margin-bottom: 12px;
    background-color: #fff;
    border-radius: 2px;
    box-shadow: 0 1px 2px 0 rgba(0,0,0,.05);
  }

  .follow-block .follow-item {
    flex: 1 1 auto;
    padding: 16px 0;
    text-align: center;
    color: #31445b;
    text-decoration: none;
  }

  .follow-block .follow-item .item-title {
    font-size: 16px;
    font-weight: 500;
  }

  .follow-block .follow-item .item-count {
    margin-top: 6px;
    font-size: 15px;
    font-weight: 600;
  }

  .more-block {
    background-color: transparent;
    border-radius: 2px;
  }

  .more-block .more-item {
    display: flex;
    padding: 15px 5px;
    font-size: 15px;
    color: #000;
    border-top: 1px solid rgba(230,230,231,.5);
  }

  .more-block .more-item .item-title {
    margin-right: auto;
  }

  a {
    text-decoration: none;
    cursor: pointer;
    color: #606060;
    color: #333;
  }

  a:hover { 
    text-decoration: none;
    cursor: pointer;
    color: #1890FF;
  }

  .recommended-books {
    padding: 0;
  }

  .sidebar-block:not(.pure) {
    background-color: #fff;
  }

  .sidebar-block {
    position: relative;
    margin-bottom: 1.5rem;
    border-radius: 2px;
  }

  .sidebar-block:not(.pure) .block-title {
    padding: 1rem 1.3rem;
    font-size: 14px;
    margin-left: 3px;
    color: #333;
    border-bottom: 1px solid hsla(0,0%,58.8%,.1);
  }

  .item {
    display: block;
    cursor: pointer;
    padding: .8rem 1.3rem;
  }

  .entry-title {
    font-size: 1.16rem;
    color: #333;
    cursor: pointer;
  }

  .entry-title:hover { 
    cursor: pointer;
  }

  .entry-meta-box {
    margin-top: .4rem;
  }

  .entry-meta {
    display: inline-block;
    margin-right: 1.5rem;
    font-size: 1.1rem;
    color: #c2c2c2;
  }

  .entry-meta .icon {
    vertical-align: sub;
  }

  .entry-meta .count {
    color: #b2bac2;
    margin-left: .4rem;
  }

  .recommended-authors .title, .recommended-books .title {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid hsla(0,0%,58.8%,.1);
  }

  .recommended-authors, .recommended-books {
      border-radius: 2px;
      overflow: hidden;
      background: #fff;
      margin-bottom: 20px;
      font-size: 13px;
      text-align: center;
      box-shadow: 0 1px 2px 0 rgba(0,0,0,.05);
  }

  .recommended-authors .title, .recommended-books .title {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid hsla(0,0%,58.8%,.1);
  }

  .recommended-authors .title span, .recommended-books .title span {
    font-size: 14px;
    color: #333;
  }

  .recommended-authors .item .link {
    padding: 12px 16px;
    display: flex;
    align-items: center;
  }

  .recommended-authors .recommended-avatar {
    display: inline-block;
    position: relative;
    background-position: 50%;
    background-size: cover;
    background-repeat: no-repeat;
    background-color: #eee;
    flex: 0 0 auto;
    width: 46px;
    height: 46px;
    border-radius: 50%;
    margin-right: 10px;
  }

  .recommended-authors .user-info {
    overflow: hidden;
    text-align: left;
  }

  .recommended-authors .username {
    font-size: 14px;
    font-weight: 400;
    color: #333;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 3px;
  }

  .recommended-authors .rank {
    margin-left: 4px;
    vertical-align: middle;
  }

  .recommended-authors .link .description, .recommended-authors .link .position {
    color: #909090;
    font-size: 12px;
    margin-bottom: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .recommended-authors .link .description, .recommended-authors .link .position {
    color: #909090;
    font-size: 12px;
    margin-bottom: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .recommended-authors .item .more {
    display: block;
    color: #ea6f5a;
    padding: 12px 0;
    text-align: center;
    border-top: 1px solid hsla(0,0%,59.2%,.1);
  }

  .recommended-books .book-item {
    padding: 15px;
    overflow: hidden;
    margin-bottom: 0;
  }

  .recommended-authors, .recommended-books {
      border-radius: 2px;
      overflow: hidden;
      background: #fff;
      margin-bottom: 20px;
      font-size: 13px;
      text-align: center;
      box-shadow: 0 1px 2px 0 rgba(0,0,0,.05);
  }

  .recommended-books .book-item a {
    display: block;
    overflow: hidden;
  }

  .recommended-books .book-item-info {
    float: left;
    width: 148px;
    margin-left: 10px;
    text-align: left;
  }

  .recommended-books .book-item-title {
    color: #333;
    font-weight: 500;
    font-size: 14px;
    margin-bottom: 5px;
  }

  .book-item-buycount {
    color: #878c90;
    float: left;
    height: 20px;
    line-height: 20px;
  }

  .try-read {
    height: 20px;
    line-height: 20px;
    color: #fff;
    font-size: 12px;
    padding-left: 5px;
    padding-right: 5px;
    border-radius: 2px;
    background-color: #007fff;
    float: right;
  }

  *, :after, :before {
      box-sizing: border-box;
  }

  .recommended-books .book-item-img {
    float: left;
    width: 52px;
    height: 72px;
  }
  
}

</style>